//
//  MainMenuDataModel.m
//  HondaPro_2
//
//  Created by Eric on 13-5-29.
//  Copyright (c) 2013年 glendale. All rights reserved.
//

#import "MainMenuDataModel.h"
#import "HelpClass.h"

@interface MainMenuDataModel ()

-(NSDictionary *)dictionaryByCustom;

@end

@implementation MainMenuDataModel

@synthesize precontractList = _precontractList;
@synthesize maintenanceList = _maintenanceList;
@synthesize settlementList = _settlementList;

@synthesize jobSheetId = _jobSheetId;
@synthesize currentRepairState = _currentRepairState;
@synthesize crrearage = _crrearage;
@synthesize carReception = _carReception;
@synthesize repairEstimate = _repairEstimate;
@synthesize repairItemList = _repairItemList;
@synthesize usePart = _usePart;
@synthesize otherChargeList = _otherChargeList;
@synthesize processingPlant = _processingPlant;
@synthesize settlementCount = _settlementCount;
@synthesize repairCarCheck = _repairCarCheck;

@synthesize waringInformation = _waringInformation;
@synthesize warrantyHistory = _warrantyHistory;
@synthesize inspectionRecord = _inspectionRecord;
@synthesize vinStr = _vinStr;
@synthesize saleDateStr = _saleDateStr;
@synthesize customerNameStr = _customerNameStr;
@synthesize expirationDateStr = _expirationDateStr;

@synthesize arrForSearchPartsInventory = _arrForSearchPartsInventory;
@synthesize strPartCodeForSearchPartsInventory = _strPartCodeForSearchPartsInventory;
@synthesize strPartChinaNameForSearchPartsInventory = _strPartChinaNameForSearchPartsInventory;
@synthesize strPartEnglishNameForSearchPartsInventory = _strPartEnglishNameForSearchPartsInventory;
@synthesize strCarTypeId = _strCarTypeId;
@synthesize strInStock = _strInStock;

@synthesize dicJobSheetMsg = _dicJobSheetMsg;
@synthesize dicBaseMessage = _dicBaseMessage;
@synthesize arrCarryGoods = _arrCarryGoods;
@synthesize arrFunctionCheck = _arrFunctionCheck;
@synthesize arrRecodeList = _arrRecodeList;
@synthesize arrImageList = _arrImageList;
@synthesize arrOutCheck = _arrOutCheck;
@synthesize arrAllocationList = _arrAllocationList;
@synthesize dicChargeDetail = _dicChargeDetail;
@synthesize nCountForResults = _nCountForResults;
@synthesize arrForResults = _arrForResults;
@synthesize nRowForResults = _nRowForResults;
@synthesize nRowForIndicationList = _nRowForIndicationList;
@synthesize nRowForRepairItemList = _nRowForRepairItemList;
@synthesize nRowForPartList = _nRowForPartList;
@synthesize nRowForOtherChargeList = _nRowForOtherChargeList;
@synthesize strCurrentCarType = _strCurrentCarType;
@synthesize strCurrentPlateNumber = _strCurrentPlateNumber;
@synthesize strCurrentCustomerName = _strCurrentCustomerName;
@synthesize strCurrentTelNumber = _strCurrentTelNumber;
@synthesize strDefaultTelNumber = _strDefaultTelNumber;
@synthesize bSendMessageState = _bSendMessageState;

@synthesize strSymptomCode = _strSymptomCode;
@synthesize strFaultCode = _strFaultCode;
@synthesize strActionCode = _strActionCode;

@synthesize jobSheetIdForPrint = _jobSheetIdForPrint;
@synthesize printTypeForPrint = _printTypeForPrint;

@synthesize arrOriginalDataForServiceType = _arrOriginalDataForServiceType;

@synthesize strCurrentSalerId = _strCurrentSalerId;
@synthesize dicSalerInfo = _dicSalerInfo;
@synthesize strCurrentPicName = _strCurrentPicName;
@synthesize strCurrentRecordName = _strCurrentRecordName;

@synthesize arrOutCheckImageNameListTmp = _arrOutCheckImageNameListTmp;

@synthesize strWhetherToDisPromoteList = _strWhetherToDisPromoteList;
@synthesize dicPromoteList = _dicPromoteList;

static MainMenuDataModel *MainMenuDataModelIns = nil;

+(MainMenuDataModel *)sharedMainMenuDataModel
{
    if (nil == MainMenuDataModelIns)
    {
        MainMenuDataModelIns = [[MainMenuDataModel alloc] init];
    }
    return MainMenuDataModelIns;
}

-(id)init
{
    if (self = [super init])
    {
        self.strSymptomCode = @"";
        self.strFaultCode = @"";
        self.strActionCode = @"";
        
        self.currentVinSel = @"";
        self.strCurrentPlateNumber = @"";
        self.strCurrentCustomerName = @"";
    }
    
    return self;
}

-(NSDictionary *)dictionaryByCustom
{
    NSMutableDictionary *theFinalDic = [NSMutableDictionary dictionary];
    
    [theFinalDic setObject:@"0" forKey:@"error_code"];
    [theFinalDic setObject:@"xxx" forKey:@"error_msg"];
    
    NSMutableDictionary *theTmpDic1 = [NSMutableDictionary dictionaryWithObjectsAndKeys:@"粤Axxx",@"plateNumber",@"10:35",@"precontractTime",@"一般修理",@"repairTypeName", nil];
    NSMutableDictionary *theTmpDic2 = [NSMutableDictionary dictionaryWithObjectsAndKeys:@"粤Axxx",@"plateNumber",@"10:40",@"precontractTime",@"一般修理",@"repairTypeName", nil];
    NSMutableArray *theTmpArr = [NSMutableArray arrayWithObjects:theTmpDic1,theTmpDic2, nil];
    [theFinalDic setObject:theTmpArr forKey:@"precontractList"];
    
    theTmpDic1 = [NSMutableDictionary dictionaryWithObjectsAndKeys:@"粤Axxx",@"plateNumber",@"张三",@"customerName",@"板金01",@"currentStation",@"13502012345",@"mobile", nil];
    theTmpDic2 = [NSMutableDictionary dictionaryWithObjectsAndKeys:@"粤Axxx",@"plateNumber",@"李四",@"customerName",@"板金02",@"currentStation",@"13502012346",@"mobile", nil];
    theTmpArr = [NSMutableArray arrayWithObjects:theTmpDic1,theTmpDic2, nil];
    [theFinalDic setObject:theTmpArr forKey:@"maintenanceList"];
    
    theTmpDic1 = [NSMutableDictionary dictionaryWithObjectsAndKeys:@"粤Axxx",@"plateNumber",@"张三",@"customerName",@"13502012345",@"mobile", nil];
    theTmpArr = [NSMutableArray arrayWithObjects:theTmpDic1, nil];
    [theFinalDic setObject:theTmpArr forKey:@"settlementList"];
    
    return theFinalDic;
}

-(id)jsonParseByJsonFileStr:(NSString *)jsonFileStr
{
    NSLog(@"%@",jsonFileStr);
    NSData *data=[NSData dataWithContentsOfFile:jsonFileStr];
    NSError *error=nil;
    id jsonObject=[NSJSONSerialization JSONObjectWithData:data
                                                  options:NSJSONReadingAllowFragments
                                                    error:&error];
    if (jsonObject != nil && error == nil)
    {
        if ([jsonObject isKindOfClass:[NSDictionary class]])
        {
            NSLog(@"NSDictionary jsonObject ->%@",(NSDictionary *)jsonObject);
            return jsonObject;
        }
        else if ([jsonObject isKindOfClass:[NSArray class]])
        {
            NSLog(@"NSArray jsonObject ->%@",(NSArray *)jsonObject);
            return jsonObject;
        }else
        {
            NSLog(@"jsonObject not NSDictionary||NSArray Class");
        }
    }
    return nil;
}

-(void)jsonWrittenToFile
{
    NSError *error=nil;
    NSData *JsonData=[NSJSONSerialization dataWithJSONObject:[self dictionaryByCustom] options:NSJSONWritingPrettyPrinted error:&error];
    if (error) {
        NSLog(@"Error %@",[error localizedDescription]);
    }
    //==Json文件路径
    NSArray *paths=NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
    NSString *path=[paths objectAtIndex:0];
    NSString *Json_path=[path stringByAppendingPathComponent:@"JsonFile.json"];
    //==写入文件
    NSLog(@"%@",[JsonData writeToFile:Json_path atomically:YES] ? @"Succeed":@"Failed");
}

-(void)jsonParseFromFile
{
    NSArray *paths=NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
    NSString *path=[paths objectAtIndex:0];
    NSString *jsonFileStr=[path stringByAppendingPathComponent:@"JsonFile.json"];
    
    NSDictionary *dic = [NSDictionary dictionaryWithDictionary:[self jsonParseByJsonFileStr:jsonFileStr]];
    NSLog(@"shitshitshit -> %@",dic);
    
    self.precontractList = [dic objectForKey:@"precontractList"];
    self.maintenanceList = [dic objectForKey:@"maintenanceList"];
    self.settlementList = [dic objectForKey:@"settlementList"];
    
    NSLog(@"_precontractList = %@",_precontractList);
    NSLog(@"_maintenanceList = %@",_maintenanceList);
    NSLog(@"_settlementList = %@",_settlementList);
}

-(void)printData
{
    NSLog(@"_precontractList = ");
    NSLog(@"%@",_precontractList);
    NSLog(@"_maintenanceList = ");
    NSLog(@"%@",_maintenanceList);
    NSLog(@"_settlementList = ");
    NSLog(@"%@",_settlementList);
}

-(void)jsonParseFromCarCalendarQueryFile
{
    // 获取当前程序包中一个资源（JsonFile.json）的路径
    NSString *jsonFilePath = [[NSBundle mainBundle] pathForResource:@"JsonFile" ofType:@"json"];
    
    NSDictionary *dic = [NSDictionary dictionaryWithDictionary:[self jsonParseByJsonFileStr:jsonFilePath]];
    
    NSLog(@"result of jsonParseFromCarCalendarQueryFile is %@",dic);
    
    //将解析的结果赋值
    
    self.jobSheetId = [dic objectForKey:@"jobSheetId"];
    self.currentRepairState = [dic objectForKey:@"currentRepairState"];
    self.crrearage = [dic objectForKey:@"crrearage"];
    self.carReception = [dic objectForKey:@"carReception"];
    self.repairEstimate = [dic objectForKey:@"repairEstimate"];
    self.repairItemList = [dic objectForKey:@"repairItemList"];
    self.usePart = [dic objectForKey:@"usePart"];
    self.otherChargeList = [dic objectForKey:@"otherChargeList"];
    self.processingPlant = [dic objectForKey:@"processingPlant"];
    self.settlementCount = [dic objectForKey:@"settlementCount"];
    self.repairCarCheck = [dic objectForKey:@"repairCarCheck"];
    
    //打印
    [self printCarCalendarQueryData];
}

-(void)fenPeiShuJuForCarCalendarQueryByDic:(NSDictionary *)dicTmp
{
    //将解析的结果赋值
    self.jobSheetId = [dicTmp objectForKey:@"jobSheetId"];
    self.currentRepairState = [dicTmp objectForKey:@"currentRepairState"];
    self.crrearage = [dicTmp objectForKey:@"crrearage"];
    self.carReception = [dicTmp objectForKey:@"carReception"];
    self.repairEstimate = [dicTmp objectForKey:@"repairEstimate"];
    self.repairItemList = [dicTmp objectForKey:@"repairItemList"];
    self.usePart = [dicTmp objectForKey:@"usePart"];
    self.otherChargeList = [dicTmp objectForKey:@"otherChargeList"];
    self.processingPlant = [dicTmp objectForKey:@"processingPlant"];
    self.settlementCount = [dicTmp objectForKey:@"settlementCount"];
    self.repairCarCheck = [dicTmp objectForKey:@"repairCarCheck"];
    
    //打印
    [self printCarCalendarQueryData];
}

-(void)printCarCalendarQueryData
{
    NSLog(@"/*---printCarCalendarQueryData---*/");
    NSLog(@"_jobSheetId = %@",_jobSheetId);
    NSLog(@"_currentRepairState = %@",_currentRepairState);
    NSLog(@"_crrearage = %@",_crrearage);
    NSLog(@"_carReception = %@",_carReception);
    NSLog(@"_repairEstimate = %@",_repairEstimate);
    NSLog(@"_repairItemList = %@",_repairItemList);
    NSLog(@"_usePart = %@",_usePart);
    NSLog(@"_otherChargeList = %@",_otherChargeList);
    NSLog(@"_processingPlant = %@",_processingPlant);
    NSLog(@"_settlementCount = %@",_settlementCount);
    NSLog(@"_repairCarCheck = %@",_repairCarCheck);
    NSLog(@"/*---end of printCarCalendarQueryData---*/");
}

-(void)jsonParseFromWaringInformationFile:(NSDictionary *)dicTmp
{
    //    NSString *jsonFilePath = [[NSBundle mainBundle] pathForResource:@"JsonFileForWaringInformation" ofType:@"json"];
    //    NSDictionary *dic = [NSDictionary dictionaryWithDictionary:[self jsonParseByJsonFileStr:jsonFilePath]];
    
    //赋值
    self.waringInformation = [dicTmp objectForKey:MM_WARING_INFORMATION_WARING_INFORMATION_LIST_KEY_STR_];
    
    self.warrantyHistory = [dicTmp objectForKey:MM_WARING_INFORMATION_WARRANTY_HISTORY_KEY_STR_];
    self.inspectionRecord = [dicTmp objectForKey:MM_WARING_INFORMATION_CHECK_RECORDS_HISTORY_KEY_STR_];
    self.vinStr = [dicTmp objectForKey:MM_WARING_INFORMATION_VIN_KEY_STR_];
    self.saleDateStr = [dicTmp objectForKey:MM_WARING_INFORMATION_SALE_DATE_KEY_STR_];
    self.customerNameStr = [dicTmp objectForKey:MM_WARING_INFORMATION_CUSTOMER_NAME_KEY_STR_];
    self.expirationDateStr = [dicTmp objectForKey:MM_WARING_INFORMATION_EXPIRATION_DATE_KEY_STR_];
    
    [self printWaringInformationData];
}

-(void)printWaringInformationData
{
    NSLog(@"/*printWaringInformationData*/");
    NSLog(@"_waringInformation = %@",_waringInformation);
    NSLog(@"_warrantyHistory = %@",_warrantyHistory);
    NSLog(@"_inspectionRecord = %@",_inspectionRecord);
    NSLog(@"/*end of printWaringInformationData*/");
}

-(void)jsonParseFromSearchPartsInventory
{
    NSString *jsonFilePath = [[NSBundle mainBundle] pathForResource:@"JsonFileForSearchPartsInventory" ofType:@"json"];
    NSDictionary *dic = [NSDictionary dictionaryWithDictionary:[self jsonParseByJsonFileStr:jsonFilePath]];
    
    //赋值
    self.arrForSearchPartsInventory = [dic objectForKey:@"results"];
    
    [self printSearchPartsInventoryData];
}

-(void)printSearchPartsInventoryData
{
    NSLog(@"/*printSearchPartsInventoryData*/");
    NSLog(@"要上传的数据：");
    NSLog(@"_strPartCodeForSearchPartsInventory = %@",_strPartCodeForSearchPartsInventory);
    NSLog(@"_strPartChinaNameForSearchPartsInventory ＝ %@",_strPartChinaNameForSearchPartsInventory);
    NSLog(@"_strPartEnglishNameForSearchPartsInventory = %@",_strPartEnglishNameForSearchPartsInventory);
    NSLog(@"_strInStock = %@",_strInStock);
    NSLog(@"要下载的数据：");
    NSLog(@"_arrForSearchPartsInventory = %@",_arrForSearchPartsInventory);
    NSLog(@"end of printSearchPartsInventoryData");
}

-(void)jsonParseFromJobSheetMake
{
    NSString *jsonFilePath = [[NSBundle mainBundle] pathForResource:@"JsonFileForResults" ofType:@"json"];
    NSDictionary *dic = [NSDictionary dictionaryWithDictionary:[self jsonParseByJsonFileStr:jsonFilePath]];
    
    NSLog(@"dic = %@",dic);
    
    //将解析出来的数据分配给 作业单编辑 的属性
    self.dicJobSheetMsg = [NSMutableDictionary dictionaryWithDictionary:dic];
    
    //基本信息可通过 在 作业单编辑 字典中按照 关键字直接取出来，故_dicBaseMessage 属性先空着

    self.arrCarryGoods = [self.dicJobSheetMsg objectForKey:@"carryGoods"];
    self.arrFunctionCheck = [self.dicJobSheetMsg objectForKey:@"functionCheck"];
    self.arrRecodeList = [self.dicJobSheetMsg objectForKey:@"recordList"];
    self.arrImageList = [self.dicJobSheetMsg objectForKey:@"imageName"];
    self.arrOutCheck = [self.dicJobSheetMsg objectForKey:@"outCheck"];
    self.arrAllocationList = [self.dicJobSheetMsg objectForKey:@"allocationList"];
    self.dicChargeDetail = [self.dicJobSheetMsg objectForKey:@"chargeDetail"];
    
    self.nCountForResults = (NSInteger)[[self.dicJobSheetMsg objectForKey:@"count"] integerValue];
    self.arrForResults = [self.dicJobSheetMsg objectForKey:@"results"];
    self.nRowForResults = -1;
    self.nRowForIndicationList = -1;
    self.nRowForRepairItemList = -1;
    self.nRowForPartList = -1;
    self.nRowForOtherChargeList = -1;
    
    //打印Log
    [self printJobSheetMakeData];
}

-(void)printJobSheetMakeData
{
    NSLog(@"/*printJobSheetMakeData*/");
    NSLog(@"_dicJobSheetMsg = %@",_dicJobSheetMsg);
    
    NSLog(@"_arrCarryGoods = %@",_arrCarryGoods);
    NSLog(@"_arrFunctionCheck = %@",_arrFunctionCheck);
    NSLog(@"_arrRecodeList = %@",_arrRecodeList);
    NSLog(@"_arrImageList = %@",_arrImageList);
    NSLog(@"_arrOutCheck = %@",_arrOutCheck);
    NSLog(@"_arrAllocationList = %@",_arrAllocationList);
    NSLog(@"_dicChargeDetail = %@",_dicChargeDetail);
    
    NSLog(@"_nCountForResults = %i",_nCountForResults);
    NSLog(@"_arrForResults = %@",_arrForResults);
    NSLog(@"_nRowForResults = %i",_nRowForResults);
    NSLog(@"_nRowForIndicationList = %i",_nRowForIndicationList);
    NSLog(@"_nRowForRepairItemList = %i",_nRowForRepairItemList);
    NSLog(@"_nRowForPartList = %i",_nRowForPartList);
    NSLog(@"_nRowForOtherChargeList = %i",_nRowForOtherChargeList);
    
    NSLog(@"/*end of printJobSheetMakeData*/");
}

-(void)fenpeiDataForJobSheet
{
    self.arrCarryGoods = [self.dicJobSheetMsg objectForKey:@"carryGoods"];
    self.arrFunctionCheck = [self.dicJobSheetMsg objectForKey:@"functionCheck"];
    self.arrRecodeList = [self.dicJobSheetMsg objectForKey:@"recordList"];
    self.arrImageList = [self.dicJobSheetMsg objectForKey:@"imageNameList"];
    self.arrOutCheck = [self.dicJobSheetMsg objectForKey:@"outCheck"];
    self.arrAllocationList = [self.dicJobSheetMsg objectForKey:@"allocationList"];
    self.dicChargeDetail = [self.dicJobSheetMsg objectForKey:@"chargeDetail"];
    
    self.nCountForResults = (NSInteger)[[self.dicJobSheetMsg objectForKey:@"count"] integerValue];
    self.arrForResults = [self.dicJobSheetMsg objectForKey:@"results"];
    self.nRowForResults = -1;
    self.nRowForIndicationList = -1;
    self.nRowForRepairItemList = -1;
    self.nRowForPartList = -1;
    self.nRowForOtherChargeList = -1;
    
    //打印Log
    [self printJobSheetMakeData];
}
-(NSMutableArray *)repairProjects{
    if (_repairProjects == nil) {
        _repairProjects = [NSMutableArray array];
    }
    return _repairProjects;
}

-(NSMutableArray *)deletedRepairProjects{
    if (_deletedRepairProjects == nil) {
        _deletedRepairProjects = [NSMutableArray array];
    }
    return _deletedRepairProjects;
}

-(NSMutableArray *)partList{
    if (_partList == nil) {
        _partList = [NSMutableArray array];
    }
    return _partList;
}

-(NSMutableArray *)deletedPartList{
    if (_deletedPartList == nil) {
        _deletedPartList = [NSMutableArray array];
    }
    return _deletedPartList;
}

-(NSMutableArray *)attachProjects{
    if (_attachProjects == nil) {
        _attachProjects = [NSMutableArray array];
    }
    return _attachProjects;
}

-(NSMutableArray *)deletedAttachProjects{
    if (_deletedAttachProjects == nil) {
        _deletedAttachProjects = [NSMutableArray array];
    }
    return _deletedAttachProjects;
}

-(NSMutableArray *)arrOutCheck{
    if (_arrOutCheck == nil) {
        _arrOutCheck = [NSMutableArray array];
    }
    return _arrOutCheck;
}
-(NSMutableArray *)arrOutCheckDeleted{
    if (_arrOutCheckDeleted == nil) {
        _arrOutCheckDeleted = [NSMutableArray array];
    }
    return _arrOutCheckDeleted;
}

-(NSMutableArray *)activeReasonArr{
    if (_activeReasonArr == nil) {
        _activeReasonArr = [NSMutableArray array];
    }
    return _activeReasonArr;
}
@end
